package com.apps.ftapp.activity;

import android.os.Bundle;
import android.widget.ListView;

import com.apps.ftapp.R;
import com.apps.ftapp.adapter.WuLiuAdapter;
import com.apps.ftapp.model.WuLiuModel;
import com.apps.ftapp.util.Async;
import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cz.msebera.android.httpclient.Header;

public class WuLiuActivity extends BaseActivity {

    @BindView(R.id.listView)
    ListView listView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;


    private Gson gson = new Gson();

    private WuLiuAdapter wuLiuAdapter;

    private List<WuLiuModel.TracesBean> dataList = new ArrayList<>();


    private String gongsi;
    private String no;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wu_liu);
        ButterKnife.bind(this);
        setTitle("物流详情");


        //新页面接收数据
        Bundle bundle = this.getIntent().getExtras();
        //接收name值
        if (null != bundle) {
            gongsi = bundle.getString("company");
            no = bundle.getString("no");
        }


        initview();
        loadData();

    }

    /**
     *
     */
    private void loadData() {

        RequestParams params = new RequestParams();
        params.put("page", 1);
        Async.post("kuaidi/HHTT/667994417806", params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                if (statusCode == 200) {
                    WuLiuModel result = gson.fromJson(new String(responseBody), WuLiuModel.class);
                    if (null != result.getTraces() && result.getTraces().size() > 0) {
                        wuLiuAdapter.addRes(result.getTraces());
                    }
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

            }
        });

    }

    private void initview() {


        wuLiuAdapter = new WuLiuAdapter(getApplicationContext(), dataList);
        listView.setAdapter(wuLiuAdapter);


    }

}
